﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace ClientChildrenBMI
{
    class Program
    {
        static void Main()
        {
            RunAsync().Wait();
        }

        static async Task RunAsync()
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:59263/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    // HTTP GET
                    HttpResponseMessage response = await client.GetAsync("api/ChildrenBMI/Peter Janul");
                    if (response.IsSuccessStatusCode)
                    {
                        var child = await response.Content.ReadAsAsync<Class5to7>();
                         // string output = (child.ChildName + " BMI : " + child.CalcBMI().ToString() + " ,which is " + child.findChildsPercentileCategory());

                        Console.WriteLine(child.ChildName + " BMI : " + child.CalcBMI().ToString() + " ,which is " + child.findChildsPercentileCategory());
                    }
                   
                    else
                    {
                        Console.WriteLine(response.StatusCode + " " + response.ReasonPhrase);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
                Console.ReadLine();
            }

        }
    }
}

//HttpResponseMessage response = await client.GetAsync("api/ChildrenBMI/");
//if (response.IsSuccessStatusCode)
//{
//    var children = await response.Content.ReadAsAsync<IEnumerable<Class5to7>>();

//    foreach (Class5to7 kid in children)
//        Console.WriteLine(children);

//}



//class Program
//{
//    static void Main(string[] args)
//    {
//        try
//        {
//   HttpClient client = new HttpClient();
//    client.BaseAddress = new Uri("http://localhost:59263/");                  // base URL for API Controller i.e. RESTFul service
//// add an Accept header for JSON
//    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// GET ../api/ChildrenBMI/parentName
//var response = client.GetAsync("api/ChildrenBMI/Peter Janul").Result;               // accessing the Result property blocks
// if (response.IsSuccessStatusCode)                                                   // 200.299
// {
//     // read result 

//     var child = response.Content.ReadAsAsync<string>().Result;

//         Console.WriteLine(child.ToString());
//     //Console.WriteLine(child);  //.ChildName + " - the BMI : " + child.CalcBMI().ToString() + " ,which consider to be in the " + child.findChildsPercentileCategory() + " category";);

// }
//// GET ../api/ChildrenBMI
//response = client.GetAsync("api/ChildrenBMI/").Result;               // accessing the Result property blocks
//if (response.IsSuccessStatusCode)                                                   // 200.299
//{
//    // read result 

//    var children = response.Content.ReadAsAsync<IEnumerable<Class5to7>>().Result;
//    foreach (Class5to7 kid in children)
//        Console.WriteLine(kid.ChildName);
//    //Console.WriteLine(child);  //.ChildName + " - the BMI : " + child.CalcBMI().ToString() + " ,which consider to be in the " + child.findChildsPercentileCategory() + " category";);

//}
//else
//{
//    Console.WriteLine(response.StatusCode + " " + response.ReasonPhrase);
//}